#pragma once

#include "strategy.h"
#include <unordered_map>
#include <deque>
#include <chrono>

namespace hft {

// 做市商策略参�?
struct MarketMakingParams {
    double spread_multiplier = 1.5;      // 价差乘数
    double min_spread = 0.0001;          // 最小价�?
    int max_position = 100;              // 最大持�?
    int order_refresh_interval = 1000;   // 订单刷新间隔(毫秒)
    int max_orders = 5;                  // 最大挂单数�?
    double position_penalty = 0.0001;    // 持仓惩罚系数
};

class MarketMakingStrategy : public Strategy {
public:
    MarketMakingStrategy(const std::string& name, const MarketMakingParams& params);

    // 策略接口实现
    bool initialize() override;
    void onMarketData(const MarketDataMessage& data) override;
    void onOrderUpdate(const OrderStatus& status) override;
    void onTrade(const Trade& trade) override;
    void start() override;
    void stop() override;
    void pause() override;
    void resume() override;

private:
    // 内部方法
    void updateQuotes();
    void cancelAllOrders();
    void placeOrder(double price, int volume, OrderSide side);
    double calculateSpread() const;
    double calculatePositionPenalty() const;
    bool shouldUpdateQuotes() const;

    // 策略参数
    MarketMakingParams params_;
    
    // 市场数据
    std::unordered_map<std::string, MarketDataMessage> latest_quotes_;
    
    // 订单管理
    std::unordered_map<std::string, OrderStatus> active_orders_;
    int current_position_ = 0;
    
    // 时间管理
    std::chrono::steady_clock::time_point last_update_time_;
    bool is_running_ = false;
};

} // namespace hft 
